home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX 6.2 Applications 1996 May
/
SGI IRIX 6.2 Applications 1996 May.iso
/
dist
/
impr_dev.idb
/
usr
/
impressario
/
src
/
examples
/
libpod
/
readlog.c.z
/
readlog.c
Wrap
C/C++ Source or Header
|
1996-05-06
|
3KB
|
117 lines
/**************************************************************************
*
* Copyright (c) 1992 Silicon Graphics, Inc.
* All Rights Reserved
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
*
* The copyright notice above does not evidence any actual of intended
* publication of such source code, and is an unpublished work by Silicon
* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
* the property of Silicon Graphics, Inc. Any use, duplication or
* disclosure not specifically authorized by Silicon Graphics is strictly
* prohibited.
*
* RESTRICTED RIGHTS LEGEND:
*
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 52.227-7013,
* and/or in similar or successor clauses in the FAR, DOD or NASA FAR
* Supplement. Unpublished - rights reserved under the Copyright Laws of
* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
* Shoreline Blvd., Mountain View, CA 94039-7311
**************************************************************************
*
* File: readlog.c
*
* Description: Sample program that demonstrates the use of the standard
* form of the libpod log file read function.
*
* Usage: readlog printer_name [num_lines]
*
* If num_lines is not specified, the entire log file will be read
* and display on standard out. If num_lines is specified, the last
* num_lines lines of the log file will be read and displayed.
*
**************************************************************************/
#ident "$Revision: 1.1 $"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <pod.h>
#define HANDLE_ERROR(pname) { \
PDPerror(pname); \
exit(1); \
}
void usage(char*);
int main(int argc, char **argv)
{
PDLogStruct *entries;
time_t mod_time;
char *printer_name;
char time_str[50];
int num_lines, actual_num;
register int i;
/*
* Get the printer name and number of lines
* from command line
*/
if (argc < 2) {
usage(argv[0]);
exit(1);
}
printer_name = argv[1];
if (argc == 3)
num_lines = strtol(argv[2], (char**)NULL, 0);
else
num_lines = PD_LOG_ALL;
/*
* Read log file
*/
if ((actual_num = PDReadLog(printer_name, num_lines,
&entries, &mod_time)) < 0)
HANDLE_ERROR(argv[0]);
/*
* Display the log file entries
*/
(void)printf("Last modified: %s\n", ctime(&mod_time));
for (i = 0; i < actual_num; i++) {
(void)cftime(time_str, "%b %d %T", &(entries[i].time_stamp));
(void)printf("%s: ", time_str);
if (entries[i].job_id)
(void)printf("%s ", entries[i].job_id);
else
(void)printf("* ");
if (entries[i].username)
(void)printf("%s ", entries[i].username);
else
(void)printf("* ");
(void)printf("0x%X ", entries[i].entry.message_code);
(void)printf("%s\n", entries[i].entry.message_text);
}
return 0;
}
void usage(char *progname)
{
(void)fprintf(stderr, "Usage: %s printer_name [num_lines]\n", progname);
}